<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\UserAskForGood;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class UserAskForGoodController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new UserAskForGood(['users','goods']), function (Grid $grid) {
            $grid->model()->orderBy('id', 'desc');
            $grid->column('id')->sortable();
            $grid->column('users.nickname',"用户");
            $grid->column('goods.name','产品');
            $grid->column('created_at')->sortable();
            // 禁用
            $grid->disableActions();
            // 禁用详情按钮
            $grid->disableViewButton();
            // 禁用编辑按钮
            $grid->disableEditButton();
            // 禁用快捷编辑按钮
            $grid->disableQuickEditButton();
            // 禁用删除按钮
            $grid->disableDeleteButton();
            // 禁用
            $grid->disableBatchActions();
            // 禁用批量删除按钮
            $grid->disableBatchDelete();
            $grid->disableCreateButton();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            // 设置datetime类型
                $filter->between('created_at')->datetime();
            });
            $titles = ['users.nickname' => '名称','users.phone'=>"手机号", 'goods.name' => '产品','created_at'=>'询价时间'];
            $grid->export($titles);
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new UserAskForGood(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('goods_id');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new UserAskForGood(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('goods_id');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
